package com.example.script.admin.util;

import com.example.script.admin.model.AdminSecurityConfig;
import com.example.script.model.AdminUser;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;


public class AdminSecurityUtils {
    private static final Logger logger= LoggerFactory.getLogger(AdminSecurityUtils.class);

    public static AdminUser getCurrentUser(){
        SecurityContext context= SecurityContextHolder.getContext();
        Authentication authentication=context.getAuthentication();
        if (authentication.getPrincipal() instanceof  String){

            return null;
        }
        AdminSecurityConfig adminSecurityConfig=(AdminSecurityConfig) authentication.getPrincipal();
        return adminSecurityConfig.getAdminUser();
    }
}
